/*
 * daemonise.h
 *
 *  Created on: Jan 5, 2010
 *      Author: user
 */

#ifndef FILEOPS_H_
#define FILEOPS_H_

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <bzlib.h>
#include <dirent.h>

#define MAXTAPE 10000
#define MAXSTRNUM 6

#define ZIPME

/* this function investigate the tape library , it will return the maximal index
 * of tape existed, and fill an array with the tapes numers.
 */
int investigate_tape_lib();

/*reads the current tape into allocated buffer, buff_size bytes
 * handles no current tape
 * updates the tape's position
 */
int read_current_tape(char* buffer,int buff_size);

/*writes the buffer onto the current tape
 * handles no current tape
 * updates the tape's position
 */
int write_current_tape(const char* buffer, int size);


/*creating a new tape, assuming current tape isn't changed
 *handles MAXNUM of tapes reached
 *handles updates the tape's position
 */
int create_tape();

/*replaces tape to tape_num
 * handles no current tape
 * handles whether we havn't created tape_num/tape_num was deleted
 * seeking to the last position of the tape
 */
int replace_tape(int tape_num);

/* rewinds the current tape
 * handles no current tape
 */
int rewind_current_tape();

/*deletes tape_num
 * handles where it was delete b4 or no such tape was created
 * updates tape position to -1
 */
int delete_tape(int tape_num);

int shutting_down();
int mybunzip(int tape_num);
int mybzip(int tape_num);

#endif /* FILEOPS_H_ */

